<template>
  <div class="stockMasterTaskDetail">
    <div class="headerBtns">
      <el-button size="small" type="primary" round icon="iconfont icon-zuo" @click="$router.go(-1)"> 返回</el-button>
    </div>
    <div class="publicSearch">
      <div class="" style="padding-left:10px">

        <el-tabs v-model="activeName" @tab-click="handleClick" style="width: 100%;">
          <el-tab-pane label="盘盈入库单" name="first">
            <div class="tableBox">
              <el-table
                      highlight-current-row
                      :data="profitList"
                      :row-key="getRowKeys"
                      height="calc(100% - 60px)"
                      :expand-row-keys="expands"
                      @expand-change="onChange"
                      style="width: 100%">
                <el-table-column
                        fixed="left"
                        type="expand"
                        label="展开"
                        width="80">
                  <template slot-scope="props">
                    <el-table
                            highlight-current-row
                            :data="goodList"
                            style="width: 96%;margin-left: 2%">
                      <el-table-column
                              prop="contCode"
                              label="容器编码"
                      ></el-table-column>
                      <el-table-column
                              prop="cellCode"
                              label="货位编码"
                      >
                      </el-table-column>
                      <el-table-column
                              show-overflow-tooltip
                              prop="itemCode"
                              label="物料编码"
                              width="180px"
                      >
                        <template slot-scope="scope">
                        <span class="textBtn"
                              @click="$parent.showPublicModal(scope.row.itemCode, 'item')">{{scope.row.itemCode}}</span>
                        </template>
                      </el-table-column>
                      <el-table-column
                              prop="itemName"
                              label="物料名称"
                              width="180px"
                      >
                        <template slot-scope="scope">
                        <span class="textBtn"
                              @click="$parent.showPublicModal(scope.row.itemCode, 'item')">{{scope.row.itemName}}</span>
                        </template>
                      </el-table-column>
                      <el-table-column
                              prop="itemPc"
                              label="物料批次"
                              width="180px"
                      ></el-table-column>
                      <el-table-column
                              label="入库量"
                      >
                        <template slot-scope="scope">
                          <div>{{scope.row.residualQuantity}}</div>
                        </template>
                      </el-table-column>

                    </el-table>
                  </template>
                </el-table-column>
                <el-table-column
                        fixed="left"
                        prop="profitLossCode"
                        label="盘盈入库单号"
                >
                </el-table-column>
                <!---->
                <el-table-column
                        prop="stockMasterCode"
                        label="盘点任务号"
                >
                </el-table-column>
                <el-table-column
                        prop="createUserName"
                        label="创建人"
                >
                </el-table-column>
                <el-table-column
                        prop="createTime"
                        label="创建时间"
                >
                </el-table-column>
              </el-table>
              <el-pagination
                      style="text-align: right"
                      class="pagination-bottom"
                      @current-change="handleCurrentChange"
                      @size-change="handleSizeChange"
                      :page-sizes="[10, 20, 30, 50]"
                      :current-page.sync="searchData.pageNum"
                      :page-size="searchData.pageSize"
                      layout="sizes, total, prev, pager, next, jumper"
                      :total="searchData.total"
              >
              </el-pagination>
            </div>

          </el-tab-pane>
          <el-tab-pane label="盘亏出库单" name="third">
            <Loss :activeName="activeName"></Loss>
          </el-tab-pane>
        </el-tabs>

      </div>
      <!--<span class="moreSearchBtn"
            :class="isMoreSearchMaster?'el-icon-caret-top':'el-icon-caret-bottom'"
            @click="isMoreSearchMaster = !isMoreSearchMaster"></span>-->
    </div>



  </div>
</template>

<script>
  import {mapState} from 'vuex'
  import Loss from './Loss'


  export default {
    name: 'profitLoss',
    components: {
      Loss,
    },
    data() {
      return {
        getRowKeys(row) {
          return row.id;
        },
        expands: [],
        isMoreSearch: false,
        isMoreSearchMaster: true,
        isMoreSearch2: false,
        activeName: 'first',

        searchData: {
          pageNum: 1,
          pageSize: 10,
          profitOrLoss: 1,
          wareId: PF.getLocal("wareId", "number"),
        },
        stockTakeMaster: {},
        profitList: [],
        goodList:[],

        searchDataItem: {
          pageNum: 1,
          pageSize: 10,
          total: null,
          keyWords: '',
          wareId: null,
          organizationId: null,
        },

        asnMaster: {},
        asnDetails: [],
        form: {
          asnMaster: {},
          asnDetails: [],
        },
        asnUdfHs: [],
        asnUdfDs: [],
        asnTypes: [],
        ids: [],
        items: [],
        suppliers: [],
        organizations: [],
        platforms: [],
        carriers: [],
        multipleSelection: [],
        qcUdfHs: [],
        qcUdfDs: [],

        innerVisibleItem: false,
        dialogNewVisible: false,
        dialogQcVisible: false,
        dialogReviewVisible: false,

        rules: {
          supplierId: [
            {required: true, message: '请选择货主', trigger: 'blur'}
          ],
          buyType: [
            {required: true, message: '请选择供应商', trigger: 'blur'}
          ],
        },

        formLabelWidth: '120px',

        formQc: {
          billSource: 0,
          insertType: -2,
          qcMaster: {},
          qcDetails: [],
        },
        rulesQc: {
          asnBillNo: [
            {required: true, message: '请选择货主', trigger: 'blur'}
          ],
          organizationId: [
            {required: true, message: '请选择供应商', trigger: 'blur'}
          ],
          supplierId: [
            {required: true, message: '请选择货主', trigger: 'blur'}
          ],
          memo: [
            {required: true, message: '请输入备注', trigger: 'blur'}
          ],
        },
        formReview: {
          billNo: this.$route.params.billNo,
          reviewResult: null,
          caseDetailId: null,
          memo: '',
        },
        rulesReview: {
          memo: [
            {required: true, message: '请填写审核原因', trigger: 'blur'}
          ],
        },

      }
    },
    computed: {
      ...mapState([
        "abcLevels",
        "stockTaskMasterType",
        "stockTaskMasterState",
        "stockTaskMasterOrder",
        "stockTaskDetailType",
        "stockTaskDetailState",
      ]),
      supplierId() {
        return this.form.asnMaster.supplierId
      },
    },
    watch: {
      supplierId(val) {
        for (let i = 0; i < this.suppliers.length; i++) {
          if (this.suppliers[i].supplierId === val) {
            this.form.asnMaster.supplierName = this.suppliers[i].supplierName;
          }
        }
      },
    },
    methods: {
      handleClick(tab, event) {
        console.log(tab, event);
      },
      handleClose3(done) {
        this.dialogReviewVisible = false;
      },
      //根据盘点任务号查询盘盈入库详情
      onChange(item,expandedRows ){
        console.log("item:",item)
        console.log("expandedRows:",expandedRows)
        if (expandedRows.length){
          this.expands = [];
          this.expands.push(item.id);
          IOT.getServerData('/stock/take/log/findProfitOrLossList', 'get', {wareId:this.searchData.wareId,stockMasterCode:item.stockMasterCode,profitOrLoss:1}, (ret) => {
            console.log("查询盘盈入库详情返回：",ret)
            if (ret.code === 200) {
              this.goodList = ret.rows
              /*this.searchData.total = ret.total
              this.searchData.pageNum = ret.pageNum*/
            } else {
              IOT.tips(ret.message || '服务器请求失败，稍后再试！', 'error');
            }
          });
        }
      },
      //查询盘盈入库单
      getProfitList() {
        IOT.getServerData("/stock/profit/loss/findByProfitLoss", 'get', this.searchData, (ret) => {
          console.log("查询盘盈入库单返回：",ret)
          if (ret.code === 200) {
            this.profitList = ret.rows;
            this.searchData.total = ret.total;
            this.searchData.pageNum = ret.pageNumber
          } else {
            IOT.tips(ret.message || '服务器请求失败，稍后再试！', 'error');
          }
        });
      },

      handleCurrentChange(val) {
        this.pageNum = val;
        this.getProfitList()
      },
      handleSizeChange(val) {
        this.searchData.pageSize = val;
        this.getProfitList();
      },
      clearSearchSelectItem() {
        this.searchDataItem.keyWords = '';
        this.searchDataItem.wareId = null;
        this.searchDataItem.organizationId = null;
      },
      handleSelectionChange(val) {
        this.multipleSelection = val;
      },
      printList() {
        this.$router.push({name: 'printView', params: {printList: this.multipleSelection}});
      },
      resetForm(formName) { // 重置
        this.$refs[formName].resetFields();
      },
      /*getCaseNowList() {
        IOT.getServerData('/case/details/nowList', 'get', {billNo: this.searchData.billNo}, (ret) => {
          if (ret.code === 200) {
            if(ret.rows.length > 0){
              this.formReview.caseDetailId = ret.rows[0].caseDetailId;
            }else{
              this.formReview.caseDetailId = null;
            }
          } else {
            IOT.tips(ret.message || '服务器请求失败，稍后再试！', 'error');
          }
        });
      },*/

    },
    created() {
      //this.getCaseNowList();
      //this.getProfitList();
      this.getProfitList();

    },
    mounted() {
    }
  }
</script>

<style scoped lang="less">
  .asnBillDetail {
  }
</style>
